package com.xzx;

import com.xzx.mybatis.mapper.BlogMapper;
import com.xzx.mybatis.po.Blog;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;

/**
 * @author xinzhixuan
 * @version 1.0
 * @date 2025/6/15 17:43
 */

public class Main {
    public static void main(String[] args) throws IOException, SQLException {
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream, "dm");
        String databaseProductName = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection().getMetaData().getDatabaseProductName();
        System.out.println(databaseProductName);
        try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
            BlogMapper mapper = sqlSession.getMapper(BlogMapper.class);
            Blog blog = mapper.selectBlog(1);
            System.out.println(blog);
        }

    }
}